import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/*
* 需要使用showCupertinoDialog，当然用showDialog也是可以的，
* 区别就是showCupertinoDialog点击弹框外是不能取消弹框的，
* showDialog是可以的，然后就是背景透明度也是不一样的
* 如果加入了国际化的话或报错'The getter alertDialogLabel was called on null'，
* 需要配置FallbackCupertinoLocalisationsDelegate
* CupertinoAlertDialog内部嵌套的是SingleChildScrollView，
* 内容超长是不会有问题的，不需要重复嵌套
* Material跟Cupertino组件也是可以混用的
*/
class CupertinoAlertDialogDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('CupertinoAlertDialog'),
        centerTitle: true,
      ),
      body: Center(
        child: RaisedButton(
          child: Text('弹窗'),
          onPressed: () {
            _myCupertinoAlertDialog(context);
          },
        ),
      ),
    );
  }

  _myCupertinoAlertDialog(BuildContext context) {
    showCupertinoDialog(
      context: context,
      builder: (context) {
        return CupertinoAlertDialog(
          title: Text('title'),
          content: Text('content'),
          actions: [
            CupertinoDialogAction(
              child: Text('取消'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
            CupertinoDialogAction(
              child: Text('确定'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
          insetAnimationDuration: Duration(seconds: 2),
        );
      },
    );
  }
}
